GHC=ghc -isrc -fwarn-missing-signatures
DATE=date
TIME=time

GHCOPT=$(GHC) -fvia-C -O3 
SOURCES=$(shell ls src/*.lhs)
UNLIT=$(subst .lhs,.hs,$(subst src,doc,$(SOURCES)))

all: bin/sergei bin/bench bin/test

sergei: bin/sergei

bench: bin/bench
	$(DATE)
	$(TIME) bin/bench +RTS -A2700k -RTS

test: bin/test
	bin/test

# no linking, no ghc optimizations:
quick: $(SOURCES)
	$(GHC) --make src/main -o /dev/null

bin/sergei: $(SOURCES)
	$(GHCOPT) --make src/main  -o bin/sergei

bin/test: $(SOURCES)
	$(GHCOPT) --make src/test  -o bin/test  -main-is Test

bin/bench: $(SOURCES)
	$(GHCOPT) --make src/bench -o bin/bench -main-is Bench

haddock: doc/index.html

doc/index.html: $(UNLIT)
	haddock -o doc -h $(UNLIT)

doc/%.hs: src/%.lhs
	ghc -e 'either putStr error . Distribution.Simple.PreProcess.Unlit.unlit "'$<'" =<< getContents' < $< > $@

clean:
	rm -f bin/* doc/* src/*.o src/*.hi src/\#*\#
